package us.quizgame;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;

import us.quizgame.database.Database;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Color;

public class SubmitQuestions extends JFrame {

	private JPanel contentPane;
	private JTextField question;
	private JTextField rightAnswer;
	private JTextField wrongAnswer;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SubmitQuestions frame = new SubmitQuestions();
					frame.setVisible(true);
					frame.setLocationRelativeTo(null);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SubmitQuestions() {
		setResizable(false);
		setTitle("The XTR3M3 Quiz Game");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 550, 450);
		contentPane = new JPanel();
		contentPane.setBackground(Color.BLACK);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblQuestion = new JLabel("Question");
		lblQuestion.setForeground(Color.WHITE);
		lblQuestion.setBounds(10, 151, 100, 14);
		contentPane.add(lblQuestion);
		
		JLabel lblRightAnswer = new JLabel("Right Answer");
		lblRightAnswer.setForeground(Color.WHITE);
		lblRightAnswer.setBounds(10, 208, 100, 14);
		contentPane.add(lblRightAnswer);
		
		JLabel lblWrongAnswer = new JLabel("Wrong Answer");
		lblWrongAnswer.setForeground(Color.WHITE);
		lblWrongAnswer.setBounds(10, 264, 100, 14);
		contentPane.add(lblWrongAnswer);
		
		question = new JTextFieldLimit(110);
		question.setBounds(137, 148, 312, 20);
		contentPane.add(question);
		question.setColumns(10);
		
		rightAnswer = new JTextFieldLimit(50);
		rightAnswer.setBounds(137, 205, 312, 20);
		contentPane.add(rightAnswer);
		rightAnswer.setColumns(10);
		
		wrongAnswer = new JTextFieldLimit(50);
		wrongAnswer.setBounds(137, 261, 312, 20);
		contentPane.add(wrongAnswer);
		wrongAnswer.setColumns(10);
		
		JButton btnSubmit = new JButton("Submit");
		btnSubmit.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				submit();
			}
		});
		btnSubmit.setBounds(99, 378, 350, 23);
		contentPane.add(btnSubmit);
		
		JLabel lblWarning = new JLabel("Warning! If you submit inappropriate information, WE WILL HUNT YOU DOWN.");
		lblWarning.setForeground(Color.WHITE);
		lblWarning.setBounds(47, 328, 447, 14);
		contentPane.add(lblWarning);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon(Menu.class.getResource("/us/quizgame/images/av-20034.png")));
		lblNewLabel.setBounds(194, 6, 150, 99);
		contentPane.add(lblNewLabel);
	}
	
	//Submits question to the database
	private void submit()
	{
		Database db = new Database();
		
		db.inputQuestion( question.getText(), rightAnswer.getText(), wrongAnswer.getText());
		
		Menu menu = new Menu();
		menu.setVisible(true);
		setVisible(false);
	}
}
